import java.util.ArrayList;


public class MyExtrapolation {
	private ArrayList<Double> EXTRADouble;
	private ArrayList<Integer> EXTRAInteger;
	
	public Double growth() {
		Double positives = 0.0;
		Double totalDifference = 0.0;
		Double last = Double.MIN_VALUE;		
		
		for (Double i : EXTRADouble) {
			if (last.equals(Double.MIN_VALUE)) {
				last = i;
			} else {
				if (i > last)
					positives++;
				totalDifference += Math.abs(i - last);
				last = i;
			}
		}
		return ( positives >= ( EXTRADouble.size() / 2 ) ) ?
				(totalDifference / EXTRADouble.size()) : 
					0 - (totalDifference / EXTRADouble.size());   
	}
	
	public Integer IntegerGrowth() {
		Integer positives = 0;
		Integer totalDifference = 0;
		Integer last = -1;
		
		
		for (Integer i : EXTRAInteger) {
			if (last.equals(-1)) {
				last = i;
			} else {
				if (i > last)
					positives++;
				totalDifference += Math.abs(i - last);
				last = i;
			}
		}
		return ( positives >= ( EXTRAInteger.size() / 2 ) ) ?
				(totalDifference / EXTRAInteger.size()) : 
					0 - (totalDifference / EXTRAInteger.size());   
	}
	
	
	public void addDouble(Double arg0) {
		EXTRADouble.add(arg0);
		while(EXTRADouble.size() > 30)
			EXTRADouble.remove(0);
	}
	
	public void setDouble(ArrayList<Double> EXTRADouble) {
		this.EXTRADouble = EXTRADouble;
	}
	
	public void addInteger(Integer arg0) {
		EXTRAInteger.add(arg0);
		while(EXTRAInteger.size() > 30)
			EXTRAInteger.remove(0);
	}
	
	public Double allowedGrowth(double[] thirty, double value) {
		double total = 0.0;
		
		for ( double d : thirty ) {
			total += d;
		}
		
		double average = total / thirty.length;
		
		if ( value > ( 1.2*average ) )
			value = value*1.2;
		else if ( value < ( 0.8*average ) )
			value = 0.8*value;
				
		return value;
	}


}
